package com.lc.reader.di

import android.content.Context
import com.lc.reader.data.database.ReaderDatabase
import com.lc.reader.data.repository.BookRepository
import com.lc.reader.data.repository.BookmarkRepository

object DependencyContainer {
    
    private var database: ReaderDatabase? = null
    private var bookRepository: BookRepository? = null
    private var bookmarkRepository: BookmarkRepository? = null
    
    fun getDatabase(context: Context): ReaderDatabase {
        if (database == null) {
            database = ReaderDatabase.getDatabase(context)
        }
        return database!!
    }
    
    fun getBookRepository(context: Context): BookRepository {
        if (bookRepository == null) {
            val db = getDatabase(context)
            bookRepository = BookRepository(db.bookDao())
        }
        return bookRepository!!
    }
    
    fun getBookmarkRepository(context: Context): BookmarkRepository {
        if (bookmarkRepository == null) {
            val db = getDatabase(context)
            bookmarkRepository = BookmarkRepository(db.bookmarkDao())
        }
        return bookmarkRepository!!
    }
}
